//
//  CHProfileVisitorView.swift
//  status
//
//  Created by 彳亍 on 2017/3/22.
//  Copyright © 2017年 彳亍. All rights reserved.
//

import UIKit

class CHProfileVisitorView: CHVisitorView {
    
    /// 顶部背景视图
    fileprivate lazy var topImageView:UIImageView = UIImageView(image: UIImage(named:"profile_cover_background") )
    /// 头像
//    fileprivate lazy var iconImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    lazy var iconImageView = UIImageView.ch_draw(image: UIImage(named: "avatar_default_big"),
                                                                size: nil,
                                                                backgroundColor: UIColor.clear,
                                                                borderColor: nil,
                                                                opaque: false)
    /// 文本
    fileprivate lazy var sloganLabel:UILabel = UILabel(text: nil, textColor: UIColor.darkGray,fontSize:12)
    /// 注册按钮
    fileprivate lazy var registerButton:UIButton = UIButton(title: "注册",
                                                            titleColor: UIColor.orange,
                                                            backgroundImage: UIImage(named:"common_button_white_disable"),
                                                            target: self,
                                                            action: #selector(register))
    /// 登录按钮
    fileprivate lazy var loginButton:UIButton = UIButton(title: "登录",
                                                         titleColor: UIColor.darkGray,
                                                         backgroundImage: UIImage(named:"common_button_white_disable"),
                                                         target: self,
                                                         action: #selector(login))
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        // 设置Ui
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// 注册
    override func register() {
         super.register()
    }
    
    /// 登录
    override func login() {
        super.login()
    }
    
    /// 访客信息
    override var visitorInfo: [String : String]? {
        didSet{
            sloganLabel.text = visitorInfo?["message"]
        }
    }
    
}

// MARK: - UI
extension CHProfileVisitorView {
    
    /// 设置UI
    fileprivate func setupUI() {
        // 1.添加视图
        addSubview(topImageView)
        insertSubview(iconImageView, aboveSubview: topImageView)
        addSubview(sloganLabel)
        addSubview(registerButton)
        addSubview(loginButton)
        
        // 2.布局
        topImageView.snp.makeConstraints { (ConstraintMaker) in
            ConstraintMaker.top.equalToSuperview().offset(64)
            ConstraintMaker.left.right.equalToSuperview()
            ConstraintMaker.height.equalTo(110)
        }
        
        iconImageView.snp.makeConstraints { (ConstraintMaker) in
            ConstraintMaker.center.equalTo(topImageView)
        }
        
        sloganLabel.snp.makeConstraints { (ConstraintMaker) in
            ConstraintMaker.centerX.equalToSuperview()
            ConstraintMaker.centerY.equalToSuperview().offset(32)
            ConstraintMaker.width.equalTo(220)
        }
        
        registerButton.snp.makeConstraints { (ConstraintMaker) in
            ConstraintMaker.top.equalTo(sloganLabel.snp.bottom).offset(8)
            ConstraintMaker.right.equalTo(sloganLabel.snp.centerX).offset(-8)
            ConstraintMaker.width.equalTo(97)
        }
        
        loginButton.snp.makeConstraints { (ConstraintMaker) in
            ConstraintMaker.top.equalTo(sloganLabel.snp.bottom).offset(8)
            ConstraintMaker.left.equalTo(sloganLabel.snp.centerX).offset(8)
            ConstraintMaker.width.equalTo(97)
        }
        
        
    }

}



